package com.xrui.hbaseview.converters;

import org.apache.hadoop.hbase.util.Bytes;

/**
 * This class is responsible for converting data from {@link byte[]}
 * to {@link String} with support of specific bytes and vice versa.
 */
public class BinaryStringConverter extends StringConverter {

    private static final long serialVersionUID = 3532868191797750281L;

    @Override
    public String toString(byte[] value) {
        if (value == null) {
            return null;
        }
        return Bytes.toStringBinary(value);
    }

    @Override
    public byte[] toBytes(String value) {
        if (value == null) {
            return EMPTY_BYTES_ARRAY;
        }
        return Bytes.toBytesBinary(value);
    }
}
